﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyPlugIn
{
    public partial class frmLogin : Form
    {
        private readonly string WhatToDo;

        public string UserName { private set; get; }

        public frmLogin(string whatToDo,string username)
        {
            InitializeComponent();

            this.Icon = null;
            this.ShowInTaskbar = false;

            WhatToDo = whatToDo;
            UserName = username;
            txtUser.Text = username;
        }

        private void FrmLogin_Load(object sender, EventArgs e)
        {
            switch (WhatToDo)
            {
                case "LOGIN":
                    {
                        this.Text = "请输入用户名和登陆密码";
                        break;
                    }
                case "CALIBRATE":
                    {
                        this.Text = "请输入用户名和校准密码";
                        break;
                    }
                default:
                    {
                        this.Text = "想干嘛?";
                        return;
                    }
            }
        }

        private void TxtPassword_KeyPress(object sender, KeyPressEventArgs e)
        {
            if((int)e.KeyChar == 13)
            {
                switch(WhatToDo)
                {
                    case "LOGIN":
                        {
                            if (txtPassword.Text == "1234")
                            {
                                UserName = txtUser.Text;
                                this.DialogResult = DialogResult.Yes;
                                return;
                            }
                            break;
                        }
                    case "CALIBRATE":
                        {
                            if (txtPassword.Text == "123456")
                            {
                                UserName = txtUser.Text;
                                this.DialogResult = DialogResult.Yes;
                                return;
                            }
                            break;
                        }
                    default:
                        {
                            this.DialogResult = DialogResult.No;
                            return;
                        }
                }
                txtPassword.SelectAll();
            }
        }
    }
}
